<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1><%= title %></h1>
    <p>Welcome to <%= title %></p>
    <table>
      <tr>
         <input id="username" type="text">
      </tr>
      <tr>
        <input id="answer" type="text">
      </tr>
    </table>

    <input onclick="connect()" value="连接" type="button">
    <input onclick="login()" value="登录" type="button">
    <input type="button" onclick="begin_class()" value="开始上课">
    <input type="button" onclick="call_name()" value="点名">
    <input type="button" onclick="send_topic()" value="发送题目">
    <input type="button" onclick="send_description()" value="发送解析">
    <input type="button" onclick="answer_question()" value="答题">
    <input type="button" onclick="check_in()" value="签到">
  </body>
  <script src="javascripts/jquery.min.js"></script>
  <script type="text/javascript">
    var url='ws://114.215.184.233:8888'
    var ws
    function connect() {
      ws=new WebSocket(url)
      ws.onopen=function () {
        console.log('open')
      }
      ws.onmessage=function (data) {
        console.log(data)
      }
      ws.onclose=function () {
        console.log('close')
      }
    }
    function login(){
      var username=$("#username").val()
      ws.send(JSON.stringify({events:'login',msg:{username:username}}))
    }
    function begin_class(){
      ws.send(JSON.stringify({events:'begin_class',data:{classId:1,teacher:'111'}}))
    }
    function call_name() {
      ws.send(JSON.stringify({events:'call_name',data:{teacher:'111',classId:'1'}}))
    }
    function send_topic() {
      ws.send(JSON.stringify({events:'send_topic',data:{teacher:'111'}}))
    }
    function send_description() {
      ws.send(JSON.stringify({events:'send_description',data:{teacher:'111',content:'题目内容',content_A:'选项A',content_B:'选项B',content_C:'选项C',content_C:'选项C',type:'单选题',answer:'A',description:'答案是A'}
      }))
    }
    function answer_question() {
      var username=$("#username").val()
      var answer=$("#answer").val()
      ws.send(JSON.stringify({events:'answer_question',data:{teacher:'111',student:username,topicId:1,answer:answer,subject:1}}))
    }
    function check_in() {
      var username=$("#username").val()
      ws.send(JSON.stringify({events:'check_in',data:{teacher:'111',student:username,classId:1}}))
    }
  </script>
</html>
